#include "statelabel.h"

StateLabel::StateLabel(QWidget *parent) :
    QLabel(parent)
{
    mStates = QVector<QString>(1, "");      // one empty state
    mCurrentState = -1;    // empty state is current
}

void StateLabel::setStates(const QVector<QString> &states)
{
    LOG(objectName(), "setStates");
    if (!states.isEmpty()){
        mStates.clear();
        mStates = states;
        setCurrentState(1);
    }
}

void StateLabel::setCurrentState(const int num)
{
    if (num>=0 && num<=stateCount())
        if (num!=mCurrentState)
        {
            mCurrentState = num;
            setText(currentStateString());
        }
}


int StateLabel::stateCount() const
{
    return mStates.count();
}

int StateLabel::currentStateNumber() const
{
    return mCurrentState;
}

QString StateLabel::currentStateString() const
{
    return mStates.at(mCurrentState);
}

void StateLabel::nextState()
{
    setCurrentState( (currentStateNumber()+1) % stateCount());
    this->setText( currentStateString() );
}






